<template>
	<view>
		<view class="my-input">
			<input type="text" v-model="title" @confirm="search" />
		</view>
		<button type="default" @click="clear">清空</button>
		<view class="his">
			
			<view v-for="(item,index) in history" class="item" @click="search2(item)">
				<text>{{item}}</text>
				<view class="icon" @click.stop="remove(index)" >
					x
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:"",
				history:uni.getStorageSync("history")||[]
			}
		},
		methods: {
			search(){
				this.history.unshift(this.title)
				this.sethis()
				uni.redirectTo({
					url:"/pages/index/index?title="+this.title
				})
				
				
			},
			sethis(){
				uni.setStorageSync("history",this.history)
			},
			remove(index){
				this.history.splice(index,1);
				this.sethis()
			},
			clear(){
				this.history=[]
				this.sethis()
			},
			search2(item){
				uni.redirectTo({
					url:"/pages/index/index?title="+item
				})
			}
			//按下历史记录的搜索
			
			
		}
	}
</script>

<style lang="scss">
.my-input{
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		background: #C7C7C7;
		input{
			width: 70%;
		}
	}
	.his{
		display: flex;
		.item{
			width: 120rpx;
			height: 50rpx;
			text-align: center;
			line-height: 50rpx;
			background: #ccc;
			margin: 10px;
			position: relative;
			.icon{
				position: absolute;
				width: 10px;
				height: 10px;
				background: green;
				right: -3px;
				top:-3px;
			}

		}
	}
</style>
